package top.hepingan.java.Aiconfig;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import dev.langchain4j.agent.tool.P;
import dev.langchain4j.agent.tool.Tool;
import io.netty.util.internal.ObjectUtil;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import top.hepingan.java.entity.AUser;
import top.hepingan.java.service.IDeviceUsageService;
import top.hepingan.java.service.IUserService;

@Component
public class userNameTools {
    @Autowired
    IUserService iUserService;
    @Autowired
    private IDeviceUsageService iDeviceUsageService;

    @Tool(name="用户名字更改",value = "返回修改成功或者失败")
    public String getUserName(@P(value="用户名", required = true)String username, @P(value="密码", required = true)String  password, @P(value="新用户名", required = true)String newusername) {

        LambdaQueryWrapper<AUser> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(AUser::getUsername,username);
        lambdaQueryWrapper.eq(AUser::getPassword,password);
      AUser user =  iUserService.getOne(lambdaQueryWrapper);
        if (user==null ){
            return "用户不存在";
        }
        user.setUsername(newusername);
        boolean update = iUserService.updateById( user);
        if (!update){
            return "修改用户名字失败";
        }
        return "修改用户名字成功";
    }
    @Tool(name = "用户是否是会员", value = "返回用户是否是会员")
    public String isMember(@P(value="用户名", required = true)String deviceId) {
        int i=iDeviceUsageService.ismember(deviceId);
        if (i==0||i<0){
            return "用户不是会员";
        }
        return "用户是会员";
    }
}
